function err = smooth_error(V,posV,T,posT,err)

% construct the VT matrix first
I = zeros(3*posT,1);
J = zeros(3*posT,1);
for tri = 1:posT
    I((tri-1)*3+1:tri*3) = T(tri,:);
    J((tri-1)*3+1:tri*3) = tri;
end
VT = sparse(I,J,ones(3*posT,1),posV,posT);

errorV = zeros(posV,1);
% begin to smooth
for i = 1:3
    for v = 1:posV
        pos = find(VT(v,:)==1);
        errorV(v) = sum(err(pos))/length(pos);
    end
    for t = 1:posT
        err(t) = sum(errorV(T(t,:)))/3;
    end
end